'
经验管理器
'

extends Node

const TARGET_EXPERIENCE_GROWHT = 5#每次升级增加的所需经验
#更新经验条
signal experience_updated(current_experience:int,target_experience:int)
signal level_up(new_level:int)#升级信号

var current_experience = 0#当前经验
var current_level = 1#当前等级
var target_experience = 5#当级所需经验

func _ready() -> void:
	GameEvents.experience_collected.connect(on_experience_collected)
	pass

#收集经验后调用增加经验函数
func on_experience_collected(number:int) -> void:
	increment_experience(number)
	pass

#增加经验，判定是否可以升级或升级多次
func increment_experience(number:int) -> void:
	current_experience = current_experience + number
	while current_experience >= target_experience:
		current_experience = current_experience - target_experience
		current_level += 1
		level_up.emit(current_level)
		target_experience += TARGET_EXPERIENCE_GROWHT
		
	experience_updated.emit(current_experience,target_experience)
	pass
